import java.util.Objects;

public class Test25 {
    public static void main(String[] args) {
            System.out.println("欢迎使用千台酒店自助订房机，请插入身份证");
            System.out.println("使用介绍，查询房间请按1,预定房间请按2，退订房间请按3，取消请按0");
            QianTai q =new QianTai();
            java.util.Scanner s= new java.util.Scanner(System.in);
        while(true) {
            System.out.print("请选择您要使用的功能");
            int i = s.nextInt();
            System.out.println();
            //使用方式关卡
        if (i >3||i<0) {
            System.out.println("输入错误！！请输入正确的数字");
            //查询房间
        }else if (i == 1) {
            System.out.println("当前客房状态：");
            q.hotelRoom();
            //预定房间
        }else if (i == 2) {
            System.out.print("请输入您要预定的房间号");
            int j =s.nextInt();
            //关卡，输入房间号是否正确
            if (j <101||j>309) {
                System.out.println("输入错误！！查无此房间");
            }else if (j >109 &&j<200) {
                System.out.println("输入错误！！查无此房间");
            }else if (j >209 && j<300) {
                System.out.println("输入错误！！查无此房间");
            }else if (j >309) {
                System.out.println("输入错误！！查无此房间");
            }else {
                q.Reserve2(j);
                System.out.println("订房成功，房间号为："+j+"\n当前客房状态");
                q.hotelRoom();
            }
            //退订房间
        }else if (i == 3) {
            System.out.print("请输入您要退订的房间号");
            int j =s.nextInt();
            //关卡，输入房间号是否正确
            if (j <101||j>309) {
                System.out.println("输入错误！！查无此房间");
            }else if (j >109 &&j<200) {
                System.out.println("输入错误！！查无此房间");
            }else if (j >209 && j<300) {
                System.out.println("输入错误！！查无此房间");
            }else if (j >309) {
                System.out.println("输入错误！！查无此房间");
            }else {
                q.Cancel(j);
                System.out.println("退房成功，房间号为："+j+"\n当前客房状态");
                q.hotelRoom();
            }
            //退出机器使用
        }else if (i == 0) {
                System.out.println("感谢您的使用再见\n");
           // System.out.println("\n欢迎使用千台酒店自助订房机，请插入身份证\n使用介绍，查询房间请按1,订房房间请按2，退订房间请按3，取消请按0");
                break;
        }
        }
    }
}
class Room extends Object{
    //实例变量
    private int serial;//房间编号
    private String roomName;//房间类型
    private boolean state;//房间状态

    //无，有参数构造方法
    public Room() {
    }
    public Room(int serial,String roomName,boolean state) {
        this.serial = serial;
        this.roomName =roomName;
        this.state =state;
    }
    //房间编号读写入口
    public int getSerial() {
        return serial;
    }
    public void setSerial(int serial) {
        this.serial = serial;
    }
    //房间类型读写入口
    public String getRoomName() {
        return roomName;
    }
    public void setRoomName(String roomName) {
        this.roomName = roomName;
    }
   //房间状态读写方法
    public boolean isState(boolean b) {
        return state;
    }
    public void setState(boolean state) {
        this.state = state;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || !(obj instanceof Room)) return false;
        Room room = (Room) obj;
        return this.getSerial() == room.getSerial();
    }

    @Override
    public String toString() {
        return "["+serial+","+roomName+","+(state?"空闲":"有客")+"]";
    }
}
class QianTai extends Object{
    //实例变量
    private Room[][]hotel;
    //构造方法
    public QianTai() {
        hotel = new Room[3][10];
        for (int i = 0; i < 3; i++) {//楼层1，2，3。数组下标0，1，2
            for (int j = 0; j < 9; j++) {
                if (i == 0) {
                    hotel[i][j] = new Room(((i + 1) * 100 + j + 1), "单人房", true);
                } else if (i == 1) {
                    hotel[i][j] = new Room(((i + 1) * 100 + j + 1), "双人房", true);
                } else {
                    hotel[i][j] = new Room(((i + 1) * 100 + j + 1), "豪华房", true);
                }
            }
        }
    }

    public QianTai(Room[][] hotel) {
        this.hotel = hotel;
    }
    public void hotelRoom(){
        for (int i = 0; i < 3; i++) {//楼层1，2，3。数组下标0，1，2
            for (int j = 0; j < 9; j++) {
                System.out.print(hotel[i][j]);
            }
            System.out.println();
        }
    }
    public void Reserve2(int serial){
       Room rooms =hotel[serial/100-1][serial%100-1];
        rooms.setState(false);
    }
    public void Cancel(int serial){
        Room rooms =hotel[serial/100-1][serial%100-1];
        rooms.setState(true);
    }
}
